@extends('mobile.layouts.layout')
@section('style')
    <link rel="stylesheet" href="{{asset("css/wapshow.css")}}" type="text/css"/>
@endsection
@section('content')
    <style>
        .footer{
            display: none;
        }
    </style>
    <div class="detail-img">
        <div class="swiper-container">
            <div class="swiper-wrapper">
                @if(count($goods['pictures']) > 0)
                    @foreach($goods['pictures'] as $picture)
                        <div class="swiper-slide">
                            <img src="{{$picture}}"/>
                        </div>
                    @endforeach
                @endif
            </div>
            <div class="swiper-pagination swiper-pagination-white"></div>
        </div>
    </div>
    <div class="detail-info">
        <p class="name goods-title">{{$goods['title']}}</p>
        <div class="goods-original-box">

            <p class="original-price">
                <span class="price"> {{!empty($item->from_site) ?$item->from_site:'淘宝'}}价 {{$goods['price']}}</span>
                <span class="volume pingfang">月销{{$goods['volume']}}</span>
            </p>
        </div>
        <div class="goods-price-box">
            <p class="goods-price">
                <span class="tips">券后</span>
                <span class="price">￥{{$goods['coupon_price']}}</span>
            </p>
        </div>
    </div>
    <div class="detail-coupon">
        <p class="coupon-amount">{{$goods['coupon_amount']}} 元优惠券</p>
        <p class="coupon-date">使用期限:{{$goods['coupon_start_time']}} ~ {{$goods['coupon_end_time']}}</p>

    </div>
    <div class="tuwen-tkl">
        <div class="pic-detail">
            <div class="pic-detail-btn" data-goodsid="{{$goods['original_id']}}">
                <span class="pic-detail-btn-span">查看图文详情<i></i></span>
            </div>
            <div class="pic-detail-show"></div>
            <span class="loadding-lab">加载中，请稍后……</span>
        </div>

    </div>
    @include('mobile.goods.go_buy')
    <div id="copy_dom"  class="copy_dom" style="display: none">{{$goods['tpwd']}}</div>
@endsection
@section('script')
    <script src="{{asset('js/clipboard.min.js')}}"></script>
    <script>
        window.mobileUtil = (function (win, doc) {
            var UA = navigator.userAgent,
                isAndroid = /android|adr|linux/gi.test(UA),
                isIOS = /iphone|ipod|ipad/gi.test(UA) && !isAndroid,
                isBlackBerry = /BlackBerry/i.test(UA),
                isWindowPhone = /IEMobile/i.test(UA),
                isMobile = isAndroid || isIOS || isBlackBerry || isWindowPhone;
            return {
                isAndroid: isAndroid,
                isIOS: isIOS,
                isMobile: isMobile,
                isWeixin: /MicroMessenger/gi.test(UA),
                isQQ: / QQ/gi.test(UA),
                isPC: !isMobile
            };
        })(window, document);

        function doLnkJump(url) {
            if (mobileUtil.isIOS){
                url = 'https://t.asc'+'zwa.com/ta'+'obao'+'?back'+'url=' + encodeURIComponent(url);
            }
            if(mobileUtil.isAndroid){
                if (mobileUtil.isQQ) {
                    var tb_url = url.replace("http://", "").replace("https://", "");
                    var ifr = document.createElement('iframe');
                    ifr.src = 'tao'+'bao'+'://' + tb_url;
                    ifr.style.display = 'none';
                    document.body.appendChild(ifr);
                    window.location.href = url;
                }else{
                    var ifr = document.createElement('iframe');
                    ifr.src = '{{url('taobao/app')}}?url='+encodeURIComponent(url);
                    ifr.style.display = 'none';
                    document.body.appendChild(ifr);
                }
            }else{
                window.location.href = url;
            }
        }

        var open = document.querySelector('.itemOpen');


        var code = '{{$code}}';
        var url = decodeURIComponent(escape(window.atob( code )));

        open.onclick = function(){
            doLnkJump( url );
        }

        //////////////////////

        var btn = document.querySelectorAll('[data-clipboard-code]');

        for( var i = 0; i < btn.length; i++ ){
            btn[i].setAttribute( 'data-clipboard-text', url );
        }

        var isLoad = false;
        var goodsId = $('.pic-detail-btn').data('goodsid');
        $('.pic-detail-btn span.pic-detail-btn-span').click(function(){
            if($('.pic-detail-show').css('display') == 'none'){
                if(!$(this).hasClass('cur')){
                    $(this).addClass('cur');
                }
                $('.pic-detail-show').css('display','block');
            }else{
                $(this).removeClass('cur');
                $('.pic-detail-show').css('display','none');
            }

            if(!isLoad){
                $('span.loadding-lab').fadeIn(300);
                setTimeout(function(){
                    $.ajax({
                        type: "get",
                        async: false,
                        url: 'http://hws.m.taobao.com/cache/mtop.wdetail.getItemDescx/4.1/?&data={"item_num_id":"'+goodsId+'"}&type=jsonp',
                        dataType: "jsonp",
                        jsonp: "callback",
                        jsonpCallback:"showTuwen",
                        success: function(jsonp){

                            $('span.loadding-lab').fadeOut(300);
                            if(jsonp.data.images.length>0){
                                for(var i = 0 ; i < jsonp.data.images.length ; i++){
                                    $('.pic-detail-show').append('<p><img src="'+jsonp.data.images[i]+'"/></p>');
                                }
                            }

                            isLoad = true;
                        },
                        error: function(){
                        }
                    });
                },300);
            }

        });



        var openApp = function(url) {
            var appUrl = url.replace("http://", "").replace("https://", "");
            var ifr = document.createElement('iframe');
            ifr.src = 'taobao://' + appUrl;
            ifr.style.display = 'none';
            document.body.appendChild(ifr);
            window.location = url;
        };
        var openAppIos9 = function(url) {
            var appUrl = url.replace("http://", "").replace("https://", ""),
                newUrl = 'taobao://' + appUrl;
            window.location = newUrl;
            window.setTimeout(function () {
                window.location = url;
            }, 3000);
        };
        var is_weixin = function() {
            var ua = navigator.userAgent.toLowerCase();
            if (ua.match(/MicroMessenger/i) == "micromessenger") {
                return true;
            } else {
                return false;
            }
        };

    </script>
@endsection